package com.jnshu.controller;

import com.jnshu.dto.person.UserDto;
import com.jnshu.exception.MyException;
import com.jnshu.service.WeChatLoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author Martin
 * @date 2019/8/5 19:02
 * 微信登录接口
 */
@Slf4j
@RestController
public class WeChatLoginCon {
    @Resource
    WeChatLoginService weChatLoginService;


    @GetMapping(value = "/u/login/code")
    public UserDto userLogin(@RequestParam("code") String code){
        //判断code码是否为空
        if (code == null){
            throw new MyException(500,"code码为空");
        }
        try {
            log.info("feign-web发送过来的code码是："+code);
            UserDto userDto = weChatLoginService.getWeChatCode(code);
            return userDto;
        }catch (Exception e){
            throw new MyException(10000,"登录失败");
        }
    }
}
